package regulation.auto.com.request;

import android.content.Context;

import com.ptjob.basecore.bean.ClientDataHull;
import com.ptjob.basecore.exception.ErrorCode;

import regulation.auto.com.api.AtuoRegulationHttpApi;
import regulation.auto.com.bean.LoginBean;
import regulation.auto.com.parser.LoginParser;

/**
 * Created by lidongming on 2016/10/19.
 */

public class RequestLoginTask extends AbstractAsyncTask<LoginBean> {
    private AsyncCallBack mAsyncCallBack;
    private String userName;
    private String passWord;


    public RequestLoginTask(Context context, String userName, String passWord, AsyncCallBack mAsyncCallBack) {
        super(context);
        this.mAsyncCallBack = mAsyncCallBack;
        this.userName = userName;
        this.passWord = passWord;
    }

    @Override
    public ClientDataHull<LoginBean> doInBackground() {
        return AtuoRegulationHttpApi.loginRequestTask(userName, passWord, new LoginParser());
    }

    @Override
    public void onPostExecute(int updateId, LoginBean result) {
        if(result != null){
            if(mAsyncCallBack != null){
                mAsyncCallBack.update(result);
            }
        } else {
            if(mAsyncCallBack != null){
                mAsyncCallBack.dataError(ErrorCode.DATA_REQUEST_NULL, null);
            }
        }
    }
    @Override
    public void netNull() {
        if(mAsyncCallBack != null){
            mAsyncCallBack.dataError(ErrorCode.NETWORK_NOT_AVAILABLE, null);
        }
    }

    @Override
    public void netErr(int updateId, String errMsg) {
        if(mAsyncCallBack != null){
            mAsyncCallBack.dataError(ErrorCode.NETWORK_REQUEST_ERROR, errMsg);
        }
    }

    @Override
    public void dataNull(int updateId, String errMsg) {
        if(mAsyncCallBack != null){
            mAsyncCallBack.dataError(ErrorCode.DATA_REQUEST_NULL, errMsg);
        }
    }


}
